Component({
  data: {
    selected: 0,
    showTabBar: true,
    color: "#626262",
    selectedColor: "#333333",
    list: [
      {
        pagePath: "/pages/index/index",
        text: "首页",
      },
      {
        pagePath: "/pages/food/food",
        text: " 点餐",
      },
      {
        pagePath: "/pages/my/my",
        text: "我的",
      },
    ],
  },
  attached() {},
  methods: {
    switchTab(e) {
      const { path, index } = e.currentTarget.dataset;
      console.log(path, index);
      if (this.data.selected === Number(index)) return;

      this.setData({
        selected: Number(index),
        showTabBar: true,
      });

      wx.switchTab({
        url: path,
        success: () => this.updateShowStatus(),
      });
    },
    // 此处需要针对中间的tabBar跳转到二级页面，而不是使用switchTab
    handleCenterClick() {
      wx.switchTab({
        url: "/pages/food/food",
        success: () => this.updateShowStatus(),
      });
    },
    updateShowStatus() {
      const pages = getCurrentPages();
      this.setData({
        showTabBar: pages.length === 1,
      });
    },
  },
});
